home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8413 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  50 lines

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: const usage as #define
  5. Date: 17 Feb 1996 22:55:44 GMT
  6. Organization: Borland International
  7. Distribution: ca
  8. Message-ID: <4g5mdg$m25@druid.borland.com>
  9. References: <4frc93$2s8@fmsu03.fm.intel.com>
  10. NNTP-Posting-Host: pbecker.borland.com
  11. Mime-Version: 1.0
  12. Content-Type: Text/Plain; charset=ISO-8859-1
  13. X-Newsreader: WinVN 0.99.5
  14.  
  15. In article <4frc93$2s8@fmsu03.fm.intel.com>, tomtzigt@frx215.intel.com says...
  16. >
  17. >We are trying to port a piece of C++ code to different platforms.
  18. >The code was developed with GNU g++, but we would like to use
  19. >the native compilers that come with the different platforms.
  20. >On IBM we use c++, on HP we use cfront, and on NT we use VC++.
  21. >Now the following situation arises: given this piece of code
  22. >
  23. >class foo {
  24. >    private:
  25. >        const int SIZE = 10;
  26. >        int array[SIZE];
  27. >    public:
  28. >        foo();
  29. >};
  30. >
  31.  
  32. I don't use GNU, so I assume this is a gnu extension. There's been a similar 
  33. change to the language definition recently, so that you can initialize static 
  34. const integral types directly in the class definition. Like this:
  35.  
  36. class foo
  37. {
  38.     static const int size = 10;
  39.     int array[size];
  40. };
  41.  
  42. const int foo::size;    // no initialization allowed here: we already did it
  43.  
  44. You can still use the other style, with no initializer in the class definition 
  45. and an explicit initializer in the definition of size. The value of size would 
  46. not be a compile-time constant, so if you did that you couldn't use it as the 
  47. size of an array.
  48.     -- Pete
  49.  
  50.